﻿namespace Ebt.Mvvm.Navigator
{
    /// <summary>
    /// The default implementation of the <see cref="IPageModel"/> interface.
    /// Could be used as a base class of view models of pages.
    /// </summary>
    public class PageModel : ViewModel, IPageModel
    {
        private bool _isPageActive;

        /// <summary>
        /// Gets the value indicating whether the page is active now.
        /// Do not change it directly.
        /// </summary>
        /// <value>
        /// <c>True</c> between <see cref="IPageModel.OnNavigatedTo"/> and <see cref="IPageModel.OnNavigatingFrom"/> calls and during them.
        /// If navigation is canceled then it does not change.
        /// </value>
        public bool IsPageActive
        {
            get { return _isPageActive; }
            set { OnPropertyChange(ref _isPageActive, value); }
        }

        /// <summary>
        /// Notifies the page model about leaving the page.
        /// </summary>
        /// <param name="navigationArgs">Contains parameters.</param>
        public virtual void OnNavigatedFrom(NavigationArgs navigationArgs)
        {
        }

        /// <summary>
        /// Override this method to be notified when navigation to a page occurred.
        /// </summary>
        /// <param name="navigationArgs">Contains parameters.</param>
        public virtual void OnNavigatedTo(NavigationArgs navigationArgs)
        {
        }

        /// <summary>
        /// Override this method to be notified when navigation from a page is about to be occurred.
        /// </summary>
        /// <returns><c>True</c> to cancel the navigation.</returns>
        public virtual void OnNavigatingFrom(ref bool cancel)
        {
        }
    }
}
